#include <stdarg.h>

#include "Framework/LogFile.h"

#include "IO/IFileSystem.h"

#include <time.h>


namespace tyro
{

	namespace Framework
	{
		LogFile::LogFile(const char* fileName, IO::IFileSystem& fileSystem)
			: fileName(fileName),
			fileSystem(fileSystem)
		{

			time_t rawtime;
			struct tm * timeinfo;
			time ( &rawtime );
			timeinfo = localtime ( &rawtime );

			Print( "LogFile created @ %s\r\n", asctime (timeinfo) );
		}

		//-----------------------------------------------------------------------------
		// Print to Log
		//-----------------------------------------------------------------------------
		void LogFile::Print(const char* message, ... )
		{
			va_list	variableArgList;
			va_start( variableArgList, message );
			char textBuffer[ 4096 ];
			vsprintf( textBuffer, message, variableArgList );
			va_end( variableArgList );

			fileSystem.Append(fileName, textBuffer);
		}

		void LogFile::PrintLineSeperator()
		{
			Print("<-------------------------------------------->\r\n");
		}

	}
}